"""
演示json和python字典相互转换
"""
import json
#准备列表，列表中每个元素都是字典，转换为Json
data = [{"name ":"张大山","age":18},{"name":"王大锤","age":19},{"name":"赵啸虎","age":20}]
json_str = json.dumps(data,ensure_ascii=False)
print(type(json_str))
print(json_str)

#准备字典,转换json
d = {"name":"周杰伦","addr":"台北"}
json_str = json.dumps(d,ensure_ascii = False)
print(type(json_str))
print(json_str)


#json转换为python数据类型
s =' [{"name ":"张大山","age":18},{"name":"王大锤","age":19},{"name":"赵啸虎","age":20}]'
l = json.loads(s)
print(type(l))
print(l)


s = '{"name":"周杰伦","addr":"台北"}'
d = json.loads(s)
print(type(d))
print(d)
